

class kind {
    constructor() {

        this.Begin();

    }
    //我方子弹移动速度
    Imove = 100
    //我方子弹产出速度
    Iproduce = 900
    //敌方飞机产出速度
    Enemyspeed=3000
    //开始时间（分）
    Starttime = 0
    //进行时间（分）
    Carrytime = 0

    time = []
    //游戏状态
    state = false;
    //分数
    fraction=0


    //开始
    Begin() {
        this.state = true;
        $(".Begin").onclick = () => {
            $(".mine").show()
            $(".Begin").none()
            if (this.state) {
                this.Airplanemoving()
            }
            this.Starttime = new Date().getMinutes();
            //我方子弹产生
            this.time[0] = setInterval(() => {
                this.Aircraftbullets()
            }, this.Iproduce)
            //敌方飞机产生
            this.time[1] = setInterval(() => {
                this.Enemyaircraftarise()
            }, this.Enemyspeed)

        }
    }
    //我的飞机移动
    Airplanemoving() {
        window.onmousemove = (e) => {
            $(".mine").style = `top:${e.clientY - $(".mine").offsetHeight / 2}px;left:${e.clientX - $(".mine").offsetWidth / 2}px`
        }
    }

    //我方子弹产生
    Aircraftbullets() {
        let left = (parseInt($(".mine").offsetLeft) + parseInt($(".mine").offsetWidth / 2) - 15)
        let top = parseInt($(".mine").offsetTop)
        let img = document.createElement("img");
        img.src = "./img/bullet.png"
        img.className = "bullet"
        img.style = `left:${left}px;top:${top}px;`
        $("body").appendChild(img)
        if (this.state = true) {
            this.Bulletsmove(img);
        }
    }
    //我方子弹移动
    Bulletsmove(img) {
        img.idd = setInterval(() => {
            img.style.top = `${parseInt(img.style.top) - 10}px`
            if (parseInt(img.style.top) < 0) {
                clearInterval(img.idd)
                $("body").removeChild(img)
            }
        }, this.Imove)
    }
    //敌方飞机产生
    Enemyaircraftarise() {
        this.Carrytime = new Date().getMinutes();

        let left = Math.random() * (window.innerWidth - 112)
        let img = document.createElement("img");
        img.className = "enemy"
        img.typee = "t";
        let lei = Math.floor(Math.random() * (5 - 1)) + 1
        img.src = `./img/Enemyaircraft${lei}.png`
        img.style = `top:0px;left:${left}px;`
        if (this.Carrytime - this.Starttime < 1) {
            img.blood = 1;
            this.Enemyspeed=3000
        } else if (this.Carrytime - this.Starttime < 3) {
            img.blood = 3;
            this.Enemyspeed=2000
        } else if (this.Carrytime - this.Starttime < 5) {
            img.blood = 6;
            this.Enemyspeed=1000
        } else if (this.Carrytime - this.Starttime < 7) {
            img.blood = 10;
            this.Enemyspeed=600
        } else {
            img.blood = 15;
            this.Enemyspeed=300
        }
        $("body").appendChild(img)

        if (this.time) {
            this.Enemyaircraftmove(img);
        }
    }
    //敌方飞机移动
    Enemyaircraftmove(img) {
        img.iidd = setInterval(() => {
            img.style.top = `${parseInt(img.style.top) + 5}px`
            if (parseInt(img.style.top) > window.innerHeight) {
                clearInterval(img.iidd)
                $("body").removeChild(img)

            } else {


                if (this.time) {
                    //飞机与飞机相撞
                    this.collision($(".mine"), img)
                    //子弹与敌方飞机
                    _(".bullet").forEach(v => {
                        this.collision(img, v)
                    })
                }
            }
        }, 100)
    }


    collision(el1, el2) {
        if (el1.offsetLeft < el2.offsetLeft + el2.offsetWidth &&
            el1.offsetLeft + el1.offsetWidth > el2.offsetLeft &&
            el1.offsetTop < el2.offsetTop + el2.offsetHeight &&
            el1.offsetHeight + el1.offsetTop > el2.offsetTop
        ) {
            let left = el1.offsetLeft;
            let top = el1.offsetTop;
            if (el2.typee == "t") {
                this.state = false;
                this.time.forEach(v => {
                    clearInterval(v)
                })

                $("body").innerHTML = `<img src="./img/deat1.gif" style="position: fixed;left:${left}px ; top: ${top}px;">`
                $("body").removeChild(el1)
                $("body").removeChild(el2)
            }


            if (el1.blood == 0) {
                clearInterval(el1.iidd)
                clearInterval(el2.idd)
                $("body").removeChild(el1)
                $("body").removeChild(el2)
                console.log("血量归零");
                this.fraction +=1;
                console.log(this.fraction)
                let fraction1=(this.fraction.toString()).split("")
                $(".fraction").innerHTML =""
                fraction1.forEach(v=>{
                    $(".fraction").innerHTML +=`<img src="./img/${v}.png">`
                    console.log(v)
                })
            } else {
                clearInterval(el2.idd)
                $("body").removeChild(el2)
                console.log("血量减");
                el1.blood -= 1;
            }

        } else {

        }
    }



}



new kind


//想法
//敌方子弹以我的飞机坐标为点
     //1.
